package com.jxl.springboot.game.utils;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * 参数转换工具
 *
 * @author 江雪林
 * @create 2021-03-20
 */
public class ParamUtils {
    public static Map<String, String> getKeyValuesMap(HttpServletRequest request) {
        Enumeration<String> parameterNames = request.getParameterNames();
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String, String> paramMap = new HashMap<String, String>();
        while (parameterNames.hasMoreElements()) {
            //获取参数值
            String name = parameterNames.nextElement();
            //获取参数值
            String[] values = request.getParameterValues(name);
            if (values.length == 1) {
                paramMap.put(name, values[0]);
            } else {
                paramMap.put(name, Arrays.toString(values));
            }
        }
        return paramMap;
    }
}
